#!/usr/bin/python3
#-*- coding: utf8 -*-
 
import  sys
import requests
import json
import ast
import logging
import datetime
 
def send_alert(to, subject, message):
    """
    新建告警到fyjumpserver
    """
    data = ast.literal_eval(message)
    headers = {'Content-Type': 'application/json;charset=UTF-8'}
    try:
        req= requests.post(url="http://core:8080/api/v1/alert/alert/create/", headers=headers, json={"to":to,"subject":subject,"message":data})
        # print(req.content)
        print(req.status_code)
    except Exception as e:
        print(e)
 

if __name__ == '__main__':
    to = sys.argv[1]
    subject = sys.argv[2]
    message = sys.argv[3]
    send_alert(to, subject, message)